package com.menglei.dailytasks.m0715;

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;

import androidx.appcompat.app.AppCompatActivity;

import com.menglei.dailytasks.R;

public class AnimActivity extends AppCompatActivity {

    private ImageView mIvContent;
    private SeekBar mSbRotate;
    private SeekBar mSbZoom;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anim);
        initView();
    }

    private void initView() {
        mIvContent = (ImageView) findViewById(R.id.iv_content);
        mSbRotate = (SeekBar) findViewById(R.id.sb_rotate);
        mSbZoom = (SeekBar) findViewById(R.id.sb_zoom);

        final Matrix matrix = new Matrix();
        Bitmap bitmap = ((BitmapDrawable) (getResources().getDrawable(R.drawable.head, null))).getBitmap();
        mSbRotate.setMax(360);
        mSbRotate.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                Bitmap bitmap = ((BitmapDrawable) (getResources().getDrawable(R.drawable.head,null))).getBitmap();
                matrix.setRotate(progress);
                bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
                mIvContent.setImageBitmap(bitmap);
                mIvContent.setRotation(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        mSbZoom.setMax(displayMetrics.widthPixels - 200);
        mSbZoom.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mIvContent.setLayoutParams(new LinearLayout.LayoutParams(progress + 200, progress + 200));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }
}